	mui.init()
				
	var timer = null 
	document.getElementById('get-vcode').addEventListener('tap',function(){
		var _self = this
		this.setAttribute('disabled',true)
		this.innerHTML = '重新发送(60秒)'
		var further = Date.now()+60000
		timer = setInterval(function(){
			var rest = ~~((further - Date.now())/1000)
			console.log(rest)
			_self.innerHTML = '重新发送('+rest+'秒)'
			if(rest<=0){
				clearInterval(timer)
				timer = null
				_self.innerHTML = '获取验证码'
				_self.removeAttribute('disabled')
			}
		},500)
		var http=getHttpHost();
		var phone=$('#phone').val();
		$.post(http+'login/send',{phone:phone},function(d){
			if(d.code!=200){
				$.toast(d.msg)
			}else{
				window.localStorage.setItem('codeId',d.data);
			}
		})
			
	})
	
	var btn_vcode = document.getElementById('get-vcode'),
		phone = document.getElementById('phone')
	phone.addEventListener('input',function(){
		//计时器存在时不进行
		if(!timer){
			btn_vcode.setDisable(!(this.value.length==11))	
		}
	})
				
	document.getElementById('quick-log').addEventListener('tap',function(){
		alert(1);
		var http=getHttpHost();
		var dataform=collectForm();
		if(checkForm(dataform)){
			return false;
		}
		$.post(http+'login/quick_login',dataform,function(d){
			//if 注册成功自动登录
			if(d.code!=200){
				mui.toast(d.msg);
			}else{
				alert(JSON.stringify(d));
				login_suc(d);
				var root = plus.webview.getWebviewById('login.html'),
				parent = plus.webview.getWebviewById('quick-reg.html')				
				mui.fire(root,'login_success',null)
				plus.webview.close(parent)
				mui.back()
			}
		})
	})



//得到表单数据
function collectForm(){
	var dataform={};
	dataform.username=$('#phone').val();
	dataform.code=$('#vcode').val();
	dataform.codeId=getuid('codeId');
	return dataform;
}

//表单验证
function checkForm(data) {
	var phone = data.username;
   
    var code = data.code;
    var codeId=data.codeId;
     var mobile_phone2 = /^1[3|4|5|7|8]\d{9}$/;
    if (phone == '' || !mobile_phone2.test(phone)) {
        mui.toast('手机号不正确');
        return true;
    }
   
    if (code == '' ) {
        mui.toast('验证码不能为空');
        return true;
    }
    
    if (!codeId){
        mui.toast('验证码错误');
        return true;
    }
}